package top.cjwtx.holy.phone.controller;

import org.apache.shiro.SecurityUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import top.cjwtx.holy.phone.config.MyAuthenticationToken;
import top.cjwtx.common.entity.R;
import top.cjwtx.holy.config.common.C;

/**
 * 登陆
 * @author 暖意
 * @date 2020年5月11日 下午9:06:04
 */
@Controller
@RequestMapping("/login")
public class LoginController extends BaseController{
	
	@RequestMapping("")
	public String login() {
		return "login";
	}
	
	/**
	 * 用户登陆
	 * @param userName 用户名
	 * @param passWord 密码
	 * @return
	 */
	@ResponseBody
	@PostMapping("/login")
	public R login(String userName,String passWord) {
		//登陆类型
		MyAuthenticationToken usernamePasswordToken = new MyAuthenticationToken(userName, passWord, C.ACCOUNT_TYPE_PHONE);
		try {
			SecurityUtils.getSubject().login(usernamePasswordToken);
		} catch (Exception e) {
			return R.error("账号或密码错误！");
		}
		return R.ok();
	}

}
